package com.wc.AlgoOJ_train.train1.c1.A111;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/12/26 10:45
 * An easy problem
 * http://43.138.190.70:8888/p/A111
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            char x = sc.next().charAt(0);
            int y = sc.nextInt();
            System.out.println(f(x) + y);
        }
    }

    static int f(char x) {
        int ans;
        if (x >= 'a') {
            ans = -(x - 'a' + 1);
        } else {
            ans = x - 'A' + 1;
        }
        return ans;
    }
}
